<!DOCTYPE html>
<html>
	<head>
		<title>我的游记</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/js/bootstrap.min.js"></script>
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/userTravels.css" />
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
		<script src="/js/plugins/dialog2/dialog.min.js"></script>


		<script>
			$(function () {
				//获取user数据
				var user = JSON.parse(sessionStorage.getItem("user"));
                console.log(user);

                //直接将currentPage写死,那么只会查询到第二页的数据,之前的data数据丢失,所以此处定义一个临时变量存放data的参数
				var dataList=[];
				var currentPage =1;
				var totalPage=0;


                //jrender渲染数据
				$.get("/users/"+user.id+"/travels",{currentPage:currentPage,pageSize:5},function (data) {

                    console.log(data);
                    $.merge(dataList,data.list)
                    $(".travels").renderValues({list:dataList},{
                        shref:function (item, value) {
                        	var href =$(item).attr("href")+value;
                        	$(item).attr("href",href);
                        }
					});
                    currentPage +=1;
                    totalPage = data.pages;
                })


				//滑动分页
				//分页的条件:屏幕的高度+滑动的高度>=文档的高度
				$(window).scroll(function () {
                    if($(window).height()+$(window).scrollTop()>=$(document).height()){
                        //console.log($(window).height());console.log($(window).scrollTop());console.log($(document).height());
                        //判断当前页是否小于等于总页数
						if(currentPage<=totalPage){
							$.get("/users/"+user.id+"/travels",{currentPage:currentPage,pageSize:5},function (data) {
								$.merge(dataList,data.list);
								$(".travels").renderValues({list:dataList},{
                                    shref:function (item, value) {
                                        var href =$(item).attr("href")+value;
                                        $(item).attr("href",href);
                                    }
                                });
                                currentPage +=1;
							})
                        }else{
                            $(document).dialog({
                                type : 'notice',
                                infoText: '亲.我也是有限度的',
                                autoClose: 2500,
                                position: 'bottom'  // center: 居中; bottom: 底部
                            });
						}
                    }
                })



            })


		</script>
	</head>

	<body>
	<div class="search-head">
		<div class="row nav-search">
			<div class="col">
				<a href="profiles.html">
					<span><i class="fa fa-chevron-left"></i></span>
				</a>
			</div>
			<div class="col">
				<span>我的游记</span>
			</div>
			<div class="col"></div>
		</div>
	</div>


	<div class="container travels">
		<dl class="list" render-loop="list">
			<dd>
				<a href="/mine/editTravels.html?id=" render-fun="shref" render-key="list.id" >
					<img render-src="list.coverUrl">
					<h6 class="title" render-html="list.title"></h6>
					<p>最近更新时间 <span render-html="list.lastUpdateTime"></span>
						<span class="span-right">
								  <i class="fa fa-heart"></i><span>0</span>收藏
							  <i class="fa fa-thumbs-o-up"></i><span>0</span>点赞</span>
					</p>
				</a>
			</dd>
		</dl>
	</div>
	</body>
</html>
